package com.carter.springframework.beans.factory.config;

//Bean定义,将Bean的class类型注册到这里
public class BeanDefinition {

    //bean的class
    private final Class<?> beanClass;

    //bean的属性和值
    private PropertyValues propertyValues = new PropertyValues();

    //初始化方法名称
    private String initMethodName;

    //销毁方法名称
    private String destroyMethodName;

    //bean作用范围，默认为单例
    private String scope = ConfigurableBeanFactory.SCOPE_SINGLETON;

    //默认启用单例模式
    private boolean singleton = true;

    //默认关闭原型模式
    private boolean prototype = false;

    public String getScope() {
        return scope;
    }

    /**
     * 对scope进行操作时，会同时改变singleton和prototype属性。
     * @param scope
     */
    public void setScope(String scope) {
        this.scope = scope;
        this.singleton = ConfigurableBeanFactory.SCOPE_SINGLETON.equals(scope);
        this.prototype = ConfigurableBeanFactory.SCOPE_PROTOTYPE.equals(scope);
    }

    public BeanDefinition(Class<?> beanClass) {
        this.beanClass = beanClass;
    }

    public BeanDefinition(Class<?> beanClass, PropertyValues propertyValues) {
        this.beanClass = beanClass;
        this.propertyValues = propertyValues;
    }

    public PropertyValues getPropertyValues() {
        return propertyValues;
    }

    public void setPropertyValues(PropertyValues propertyValues) {
        this.propertyValues = propertyValues;
    }

    public Class<?> getBeanClass(){
        return beanClass;
    }

    public String getInitMethodName() {
        return initMethodName;
    }

    public void setInitMethodName(String initMethodName) {
        this.initMethodName = initMethodName == null ? null : initMethodName.trim();
    }

    public String getDestroyMethodName() {
        return destroyMethodName;
    }

    public void setDestroyMethodName(String destroyMethodName) {
        this.destroyMethodName = destroyMethodName == null ? null : destroyMethodName.trim();
    }

    public boolean isSingleton() {
        return singleton;
    }

    public void setSingleton(boolean singleton) {
        this.singleton = singleton;
    }

    public boolean isPrototype() {
        return prototype;
    }

    public void setPrototype(boolean prototype) {
        this.prototype = prototype;
    }
}
